<?php
class user_model extends MY_model
{
    public $id;
    public $username;
    public $password;
    public $user_group_code;
    public $note;
    public $modified_date;

    public function get_elements()
    {
        $query = $this->db->query("SELECT * FROM user");
        return $this->to_domain_models($query->result());
    }

    public function get_element_by_id($id)
    {
        $query = $this->db->query("SELECT * FROM user WHERE id = ?",array($id));
        return $this->to_domain_model($query->row());
    }

    public function get_element_by_username_and_password($username,$password)
    {
        $query = $this->db->query("SELECT * FROM user WHERE username = ? AND password = ?",array($username,$password));
        return $this->to_domain_model($query->row());
    }

    // -------------------------------------------------------------------------------- PRIVATE METHOD

    // Private method
    public function to_domain_model($item)
    {
        $model = new user_model();
        $model->id = isset($item->id) ? $item->id : '' ;
        $model->username = isset($item->username) ? $item->username : '' ;
        $model->password = isset($item->password) ? $item->password : '' ;
        $model->user_group_code = isset($item->user_group_code) ? $item->user_group_code : '';
        $model->note = isset($item->note) ? $item->note : '';
        $model->modified_date = isset($item->modified_date) ? $item->modified_date: '';
        return $model;
    }
}